package cn.seem.resolver;

import cn.seem.exception.Wn32Exception;
import org.springframework.web.servlet.HandlerExceptionResolver;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * 自定义异常处理器
 */
public class Wn32ExceptionResolver implements HandlerExceptionResolver {
    @Override
    public ModelAndView resolveException(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) {
        Wn32Exception we = null;
        //-- 判断当前的异常是不是Wn32Exception
        if (ex instanceof Wn32Exception)
            we = (Wn32Exception) ex;
        else
            we = new Wn32Exception("【系统错误,请与管理员联系】");

        ModelAndView mv = new ModelAndView();
        mv.setViewName("error");
        mv.addObject("msg",we.getMessage());
        return mv;
    }
}
